package com.school.movie.business.web.controller;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

/**
 * @author zhaoren
 * @version 1.0
 * @description 页面控制器, 用于普通页面的跳转，而不要是经过一些复杂处理的controller
 * @date 2020/9/14 15:13
 **/
@Controller
public class PageController {

    @Value("${FRONT}")
    private String FRONT_PREFIX;


    /**
     * 根目录下跳转首页
     *
     * @return
     */
    @GetMapping("/")
    public String toIndex() {
        return "/front/index/index";
    }

    /**
     * 前台简单页面跳转
     *
     * @param page
     * @param redirect
     * @param model
     * @return
     */
    @GetMapping("page/{page}")
    public String frontPage(@PathVariable(name = "page") String page, String redirect, Model model) {
        //如果需要重定向，将redirect信息放入跳转的视图中
        if (StringUtils.isNotBlank(redirect)) {
            model.addAttribute("redirect", redirect);
        }
        return FRONT_PREFIX + "/" + page;
    }


}
